// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'font-awesome/css/font-awesome.css'
Vue.use(ElementUI)

Vue.config.productionTip = false
import api from './axios/index.js';
Vue.prototype.$api = api;
import url from './api/index.js'
Vue.prototype.$url = url
import store from './store/index.js'
/* eslint-disable no-new */
import './assets/dataPOOL'

router.beforeEach((to, from, next) => {
    store.state.userMsg = localStorage.getItem('userMsg') //获取本地存储的token
    if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
        if (store.state.userMsg !== null || '') { // 通过vuex state获取当前的token是否存
            next();
        } else {
            this.$message({
                message: "该页面需要登录",
                type: "success"
            });
            next({
                path: '/login',
            })
        }
    } else {
        next();
    }
})
new Vue({
    el: '#app',
    router,
    store,
    components: { App },
    template: '<App/>'
})